import userServices from '@/services/userService.js';
import { ACSSESS_USER, ACCESS_TOKEN } from "@/common/utils/constants.js";

export default {
	data() {
		return {
			showPassword: false,
			agree: false,
			fromData: {
				username: '',
				password: ''
			}
		}
	},
	methods: {
		onChangePassword: function() {
			this.showPassword = !this.showPassword;
		},
		async onLogin() {
			if (!this.agree) {
				this.$message.error('请同意协议');
				return;
			}
			if (!this.fromData.username) {
				this.$message.error('请输入账号');
				return;
			}
			if (!this.fromData.password) {
				this.$message.error('请输入密码');
				return;
			}
			var result = await userServices.login(this.fromData);
			this.$store.commit({ type: 'setToken', token: result.token } );
			await uni.setStorageSync(ACCESS_TOKEN, result.token );
			this.$tool.goToPage('/pages/Tabbar/XunJian/index','','switchTab');
		}
	}
}